Repository navigation
Make the records append rollback-safe and validate record shapes - #207
Merged
Merged
Conversation
The records file is now replaced atomically (old bytes plus new lines, written and synced in a temporary file) and a failed publication restores both the description and the records. read_records refuses any line that is not one of the three Spec record types with exactly that type's keys. Fixes #206 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Scma6W3LC11s3qjXHZuGDm
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Scma6W3LC11s3qjXHZuGDm # Conflicts: # CHANGELOG.md
guijacquemet
pushed a commit
that referenced
this pull request
Nov 7, 2026
main now validates each record against the Spec record shapes (#207), so the four-key record this test wrote was refused and nothing was run. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Scma6W3LC11s3qjXHZuGDm
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #206
What changed and why
_append_recordsno longer appends to the livemorphobricks.records.jsonl. It builds old bytes plus new lines, writes them to a synced temporary file in the same folder, and replaces the live file in one atomic replace. A failure inwrite,flushorfsyncleaves the live file untouched and removes the temporary file.publish_descriptionnow puts back both the description and the records bytes (or removes the records file if there was none) when the append fails.read_recordsrefuses any line that is not one of the Spec record types (reconfirmation,image_count_changed,removed) with exactly that type's key set (Spec main964f097,docs/experiment-v1.mdsection 4.6).{}was accepted before.tests/test_spec_encoding.py: the non-ASCII record now carries all keys of areconfirmationrecord (it was an incomplete record that the new validation refuses).The durability of the records write is as before (temporary file is fsynced before the replace); the directory is not fsynced, as for the description.
Regression tests (
tests/test_description_file.py)On the old code (
origin/mainsource, new tests): 12 failed, 23 passed. On the new code: all 35 pass.Failing on old code:
test_a_write_that_fails_inside_the_append_leaves_file_and_records_as_before(4 cases: no records file or existing records, times partial bytes or full bytes written before the failure)test_a_failed_fsync_of_the_records_leaves_file_and_records_as_beforetest_a_records_file_that_is_not_lines_of_spec_records_is_refused(7 new cases:{}, type only, unknown type, no type, extra key, renamed key, partialremoved)Also added
test_a_record_whose_hash_is_not_the_published_file_is_history_not_an_error(passes on both).Checks
ruff check .: all checks passed;ruff format --check .: 293 files already formatted;python tools/check.py --rules: passed.pytest: 7 failed, 3811 passed, 25 skipped. The 7 failures are all intests/test_notebook_setup.pyand also fail on unmodifiedorigin/main(1c54f4e; 7 failed, 4 passed in that file): pre-existing, not touched. The 25 skips are optional-dependency skips (for exampleipywidgetsnot installed); skipped tests were not run.Generated by Claude Code